package com.best.oasis.settlement.web.authentication;

import java.security.Principal;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.security.AuthenticationResultUtils;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import com.best.oasis.settlement.common.vo.security.UserVO;
import com.best.oasis.settlement.loginservice.LoginService;
import com.best.oasis.settlement.service.security.UserService;

@RemotingDestination
@Service
public class AuthenticationAction {
	@Autowired
	private LoginService loginService;
	@Autowired
	private UserService userService;
	
    public Map<String, Object> getAuthentication() {
        return AuthenticationResultUtils.getAuthenticationResult();
    }
    /**
     * 
     * {@inheritDoc}
     */
    public Principal login(String username, String password) {
        /*Authentication authentication = this.authManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
        LdapUserDetailsImpl ldapUserDetailsImpl ;
        User user = null;
        if(authentication.getPrincipal() instanceof LdapUserDetailsImpl){
        	ldapUserDetailsImpl = (LdapUserDetailsImpl)authentication.getPrincipal();
        	user = userService.getBy("username", ldapUserDetailsImpl).getUsername());
        }
        SecurityContextHolder.getContext().setAuthentication(authentication);*/
    	return loginService.login(username, password);
    }
    /**
     * 
     * {@inheritDoc}
     */
    public boolean doLogout() {
        SecurityContextHolder.clearContext();
        return true;
    }
	/**
	 *  获得当前登录用户信息
	 *
	 */
    public UserVO getLoginUser(){
    	return userService.getLoginUser();
    }
}
